package easy;

public class Solution_896 {

    public boolean isMonotonic(int[] nums) {
        int sub = 0;
        for (int i = 1; i < nums.length; i++) {
            int a = nums[i] - nums[i - 1];
            if ((sub > 0 && a < 0) || (sub < 0 && a > 0)) {
                return false;
            }
            sub += a;
        }
        return true;
    }

    public static void main(String[] args) {
        Solution_896 model = new Solution_896();
        System.out.println(model.isMonotonic(new int[]{1, 2, 2, 3}));
        System.out.println(model.isMonotonic(new int[]{6, 5, 4, 4}));
        System.out.println(model.isMonotonic(new int[]{1, 3, 2}));
        System.out.println(model.isMonotonic(new int[]{1, 2, 4, 5}));
        System.out.println(model.isMonotonic(new int[]{1, 1, 1}));
        System.out.println(model.isMonotonic(new int[]{11, 11, 9, 4, 3, 3, 3, 1, -1, -1, 3, 3, 3, 5, 5, 5}));
    }
}
